package frame.factory;

import frame.pojo.Configuration;
import frame.config.XMLConfiguratorBuilder;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * FileName: SqlSessionFactoryBuilder
 * Author:   xuan zongjun
 * Date:     2020/11/6 11:57
 * Description:
 */


public class SqlSessionFactoryBuilder {


    /**
     * 创建sqlSessionFactory
     * @return
     */
    public  SqlSessionFactory  builder(InputStream inputStream) throws DocumentException, PropertyVetoException, ClassNotFoundException {
        //1. 解析配置文件，封装Configuration
        XMLConfiguratorBuilder xmlConfiguratorBuilder = new XMLConfiguratorBuilder();
        Configuration configuration = xmlConfiguratorBuilder.parseConfiguration( inputStream );

        //2. 创建 sqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory( configuration );

        return sqlSessionFactory;
    }
}
